package com.example.helper2;

import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.fragment.app.DialogFragment;

public class fragment_card_show extends DialogFragment {
    private TextView title;
    private TextView type;
    private TextView content;

    private TextView testView;

    // 根据传递的值进行查找
    private int id;
    // 数据库的处理方式
    private SQLiteDatabase sqL_read;
    // 获得查找到的卡片信息
    private HomeCardInfo cardInfo;


    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        // 获取Fragment传递过来的值
        Bundle bundle = getArguments();
        if (bundle != null){
            id = bundle.getInt("id");
        }

        View view = inflater.inflate(R.layout.dialogview,container,false);

        title = view.findViewById(R.id.dialog_title);
        type = view.findViewById(R.id.dialog_type);
        content = view.findViewById(R.id.dialog_content);

        // 连接数据库
        home_card_database cards = new home_card_database(getActivity());
        sqL_read = cards.getReadableDatabase();
        // 根据传递过来的值进行查询
        cardInfo = cards.querydatabyid(sqL_read,id);
        // 更新数据
        title.setText(id+". "+cardInfo.getTitle());
        type.setText(cardInfo.getType());
        content.setText(cardInfo.getContent());

        return view;
    }


}
